<?php

namespace App\Http\Controllers\Counter;

use App\Http\Controllers\Controller;
use App\Http\Resources\CRM\CategoryResource;
use App\Models\Category;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class CategoryController extends Controller
{
    public function getList(Request $request)
    {
        $storeId = $request->store_id ?? Auth::user()->store_id;

        $categories = Category::oldest("sort")->with("goods")->with([
            'goods.stocks' => function ($query) use($storeId) {
                $query->where("store_id", $storeId);
            }
        ])->paginate();

        return CategoryResource::collection($categories);
    }
}
